<!DOCTYPE html>
<html lang="en">
<head>
    <title>仓位在线</title>
    {% include 'admin/common/header.html' %}
    <link rel="stylesheet" href="{{ url_for('static', filename='admin/admin/css/other/user.css') }}"/>
</head>
<body class="pear-container">
{# 查询表单 #}
<div class="layui-card">
    <div class="layui-card-body">
        <form class="layui-form" action="" lay-filter="mail-query-form">
            <div class="layui-form-item">
                <label class="layui-form-label">切片日期</label>
                <div class="layui-input-inline">
                    <select name="createDate" id="createDate">
                        {% for createDate in create_dates %}
                            <option value="{{ createDate }}">{{ createDate }}</option>
                        {% endfor %}
                    </select>
                </div>
                <label class="layui-form-label">公司行业</label>
                <div class="layui-input-inline">
                    <select name="industry" id="industry">
                        <option value="">请选择</option>
                        {% for industry in industrys %}
                            <option value="{{ industry[0] }}">{{ industry[0] }}-{{ industry[1] }}</option>
                        {% endfor %}
                    </select>
                </div>
                <label class="layui-form-label">控盘程度</label>
                <div class="layui-input-inline">
                    <select name="manipulate" id="manipulate">
                        <option value="">请选择</option>
                        {% for manipulate in manipulates %}
                            <option value="{{ manipulate }}">{{ manipulate }}</option>
                        {% endfor %}
                    </select>
                </div>
                <label class="layui-form-label">平均仓位</label>
                <div class="layui-input-inline">
                    <select name="controlLevel" id="controlLevel">
                        <option value="">请选择</option>
                        {% for controlLevel in control_levels %}
                            <option value="{{ controlLevel }}">{{ controlLevel }}</option>
                        {% endfor %}
                    </select>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">资金动向</label>
                <div class="layui-input-inline">
                    <select name="averagePosi" id="averagePosi">
                        <option value="">请选择</option>
                        {% for averagePosi in average_posis %}
                            <option value="{{ averagePosi }}">{{ averagePosi }}</option>
                        {% endfor %}
                    </select>
                </div>
                <label class="layui-form-label">市盈率</label>
                <div class="layui-input-inline">
                    <input type="text" name="startPerTtm" placeholder="" class="layui-input">
                </div>
                <div class="layui-input-inline">
                    <input type="text" name="endPerTtm" placeholder="" class="layui-input">
                </div>
                <label class="layui-form-label">股票代码</label>
                <div class="layui-input-inline">
                    <input type="text" name="stockCode" placeholder="" class="layui-input">
                </div>
                <button class="pear-btn pear-btn-md pear-btn-primary" lay-submit lay-filter="mail-query">
                    <i class="layui-icon layui-icon-search"></i>
                    查询
                </button>
                <button type="reset" class="pear-btn pear-btn-md">
                    <i class="layui-icon layui-icon-refresh"></i>
                    重置
                </button>
            </div>
        </form>
    </div>
</div>
{# 用户表格 #}
<div class="user-main user-collasped">
    <div class="layui-card">
        <div class="layui-card-body">
            <table id="mail-table" lay-filter="mail-table"></table>
        </div>
    </div>
</div>
</body>
{# 表格操作 #}
<script type="text/html" id="mail-toolbar">
    {% if authorize("admin:mail:add") %}
        <button class="pear-btn pear-btn-primary pear-btn-md" lay-event="add">
            <i class="pear-icon pear-icon-add"></i>
            新增
        </button>
    {% endif %}
    {% if authorize("admin:mail:remove") %}
        <button class="pear-btn pear-btn-md" lay-event="batchRemove">
            <i class="pear-icon pear-icon-ashbin"></i>
            删除
        </button>
    {% endif %}
</script>

{% include 'admin/common/footer.html' %}

<script>
  layui.use(['table', 'form', 'jquery', 'popup', 'common'], function () {
    let table = layui.table
    let form = layui.form
    let $ = layui.jquery
    let dtree = layui.dtree
    let popup = layui.popup
    let common = layui.common
    let MODULE_PATH = '/fund/'

    // 表格数据
    let cols = [
      [ { title: '股票名词', field: 'stock_name', align: 'center', templet: function (d) {
          return '<a href="' + d.xq_url + '" target="_blank">' + d.stock_name + '</a>'
        } },
        { title: '股票编码', field: 'stock_code', align: 'center' },
        { title: '当前价格', field: 'cur_price', align: 'center' },
        { title: '市盈率', field: 'per_ttm', align: 'center' },
        { title: '区间涨幅', field: 'rises', align: 'center' },
        { title: '收入增长率', field: 'm_busi_income1', align: 'center' },
        { title: '净利润增长率', field: 'n_profit_grate1', align: 'center' },
        { title: '净资产增长率', field: 'n_assert_grate1', align: 'center' },
        { title: '今日总评', field: 't_grade', align: 'center' },
        { title: '机构参与度', field: 'participation', align: 'center' },
        { title: '控盘程度', field: 'manipulate', align: 'center' },
        { title: '平均仓位', field: 'control_level', align: 'center' },
        { title: '资金动向', field: 'average_posi', align: 'center' },
        { title: '行业', field: 'industry', align: 'center' },
        { title: '价值评估', field: 'value_assessment', align: 'center' },
        { title: '机构预测数量', field: 'organ_num', align: 'center' }
      ]
    ]

    // 渲染表格数据
    table.render({
      elem: '#mail-table',
      url: MODULE_PATH + 'data',
      page: true,
      limit: 15,
      cols: cols,
      skin: 'line',
      height: 'full-148',
      toolbar: '#mail-toolbar', /*工具栏*/
      text: { none: '暂无数据' },
      defaultToolbar: [{ layEvent: 'refresh', icon: 'layui-icon-refresh' }, 'filter', 'print', 'exports'] /*默认工具栏*/
    })



    table.on('tool(mail-table)', function (obj) {
      if (obj.event === 'remove') {
        window.remove(obj)
      }
    })

    table.on('toolbar(mail-table)', function (obj) {
      if (obj.event === 'add') {
        window.add()
      } else if (obj.event === 'refresh') {
        window.refresh()
      } else if (obj.event === 'batchRemove') {
        window.batchRemove(obj)
      }
    })

    form.on('submit(mail-query)', function (data) {
      window.refresh(data.field)
      return false
    })

    window.add = function () {
      layer.open({
        type: 2,
        title: '新增',
        shade: 0.1,
        area: ['550px', '550px'],
        content: MODULE_PATH + 'add'
      })
    }


    window.remove = function (obj) {
      layer.confirm('确定要删除', { icon: 3, title: '提示' }, function (index) {
        layer.close(index)
        let loading = layer.load()
        $.ajax({
          url: MODULE_PATH + 'remove/' + obj.data['id'],
          dataType: 'json',
          type: 'delete',
          success: function (result) {
            layer.close(loading)
            if (result.success) {
              popup.success(result.msg, function () {
                obj.del()
              })
            } else {
              popup.failure(result.msg)
            }
          }
        })
      })
    }

    window.batchRemove = function (obj) {
      let data = table.checkStatus(obj.config.id).data
      if (data.length === 0) {
        layer.msg('未选中数据', {
          icon: 3,
          time: 1000
        })
        return false
      }
      var ids = []
      var hasCheck = table.checkStatus('mail-table')
      var hasCheckData = hasCheck.data
      if (hasCheckData.length > 0) {
        $.each(hasCheckData, function (index, element) {
          ids.push(element.id)
        })
      }
      {#console.log(ids);#}
      layer.confirm('确定要删除选中数据', {
        icon: 3,
        title: '提示'
      }, function (index) {
        layer.close(index)
        let loading = layer.load()
        $.ajax({

          url: MODULE_PATH + 'batchRemove',
          data: { ids: ids },
          dataType: 'json',
          type: 'delete',
          success: function (result) {
            layer.close(loading)
            if (result.success) {
              popup.success(result.msg, function () {
                table.reload('mail-table')
              })
            } else {
              popup.failure(result.msg)
            }
          }
        })
      })
    }

    window.refresh = function (param) {
      table.reload('mail-table', { where: param })
    }
  })
</script>
</html>